package com.slkj.shilixiaoyuanapp.ui.teacher.tool.meeting;

import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.api.InjectParam;
import com.slkj.shilixiaoyuanapp.R;
import com.slkj.shilixiaoyuanapp.base.ActivityInfo;
import com.slkj.shilixiaoyuanapp.base.BaseActivity;
import com.slkj.shilixiaoyuanapp.data.UserRequest;
import com.slkj.shilixiaoyuanapp.entity.ToolMeetingDetailEntity;
import com.slkj.shilixiaoyuanapp.net.HttpHeper;
import com.slkj.shilixiaoyuanapp.net.callback.CommonCallBack;
import com.slkj.shilixiaoyuanapp.ui.common.ChosePeopleActivity;
import com.slkj.shilixiaoyuanapp.view.NumberEditText;
import com.slkj.shilixiaoyuanapp.view.StateLayout;
import com.slkj.shilixiaoyuanapp.view.dialog.LoadSuccessAndFailDialog;

import butterknife.BindView;
import butterknife.OnClick;

@ActivityInfo(layout = R.layout.activity_meeting_dsp, title = "待审批")
public class MeetingDspActivity extends BaseActivity {
    @InjectParam
    int id;
    @InjectParam
    ToolMeetingDetailEntity data;
    @BindView(R.id.tv_yhry)
    TextView tvYhry;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.edit_pos)
    EditText editPos;
    @BindView(R.id.edit_name)
    EditText editName;
    @BindView(R.id.tv_spr)
    TextView tvSpr;
    @BindView(R.id.tv_user_name)
    TextView tvUserName;
    @BindView(R.id.tv_now_day_time)
    TextView tvNowDayTime;
    @BindView(R.id.layout_root)
    StateLayout stateLayout;
    @BindView(R.id.edit_content)
    NumberEditText editContent;
    @BindView(R.id.tv_cb)
    TextView tvCb;
    @BindView(R.id.iv_select_spr)
    ImageView iv_select_spr;
    @Override
    protected void init() {
        MeetingDspActivity__JumpCenter.bind(this);
        tvUserName.setText(UserRequest.getInstance().getUser().getUser().getUName());
        tvNowDayTime.setText(data.getApplyDate());
        setViewData();
        iv_select_spr.setVisibility(View.GONE);
    }

    /**
     * 获取数据成功设置数据
     */
    private void setViewData() {
        tvYhry.setText(ChosePeopleActivity.getPeoplesInfos(data.getTeacherName()));
        tvTime.setText(data.getDatetime());
        editName.setText(data.getTitle());
        editPos.setText(data.getPlace());
        editContent.setText(data.getBody());
        tvSpr.setText(ChosePeopleActivity.getPeoplesInfos(data.getAuditor()));

        tvCb.setEnabled(!data.isUrge());
    }

    /**
     * 删除。
     */
    @OnClick(R.id.tv_cx)
    void delete() {
        HttpHeper.get().toolService()
                .toolDelete("Evection/deleteByIdAuditEvection.do", id)
                .compose(bindToLifecycle()).compose(getThread())
                .subscribe(new CommonCallBack<String>(true,this) {
                    @Override
                    public void onCallBackSuccess(String data) {
                        LoadSuccessAndFailDialog.showSuccess(MeetingDspActivity.this,data);
                        finish();
                    }
                });
    }

    /**
     * 催办
     */
    @OnClick(R.id.tv_cb)
    void cb() {
        HttpHeper.get().toolService()
                .cb(ChosePeopleActivity.getIdList(data.getAuditor()).toString(),id)
                .compose(bindToLifecycle()).compose(getThread())
                .subscribe(new CommonCallBack<String>(true,this) {
                    @Override
                    public void onCallBackSuccess(String data) {
                        LoadSuccessAndFailDialog.showSuccess(MeetingDspActivity.this,data);
                        tvCb.setEnabled(false);
                    }
                });
    }

}
